@extends('admin.layout.index')
@section('title','分类列表')
@section('content')
<div class="row">
	<div class="col-lg-12">
	    <h1 class="page-header">分类列表</h1>
	</div>
</div>


<div class="col-lg-12">
	<div class="panel panel-default">
	    <div class="panel-heading">

	    </div>
	    <!-- /.panel-heading -->
	    <div class="panel-body">
	        <div class="dataTable_wrapper">
	            <div id="dataTables-example_wrapper" class="dataTables_wrapper form-inline dt-bootstrap no-footer">
	            	<!-- 搜索的表单 -->
	            	<form action="{{url('/admin/cate/index')}}" method="get">
		            	<div class="row">
		            		<div class="col-sm-8">
		            			<div class="dataTables_length" id="dataTables-example_length">
		            				<label> 显示 
		            					<select name="num" aria-controls="dataTables-example" class="form-control input-sm">
			            					<option value="10"
											@if(!empty($request['num']) && $request['num'] == 10)
												selected
											@endif
			            					>10</option>
			            					<option value="15"
											@if(!empty($request['num']) && $request['num'] == 15)
												selected
											@endif
			            					>15</option>
			            					<option value="20"
											@if(!empty($request['num']) && $request['num'] == 20)
												selected
											@endif
			            					>20</option>
			            					<option value="25"
											@if(!empty($request['num']) && $request['num'] == 25)
												selected
											@endif
			            					>25</option>
		            					</select> 条
		            				</label>
		            			</div>
		            		</div>
	            			<div class="col-sm-4">
	            				<div id="dataTables-example_filter" class="dataTables_filter">
	            					<!-- 搜索 -->
	            					<label><input 
	            							@if(!empty($request['keywords']))
	            								value="{{$request['keywords']}}" 
											@endif
	            							type="search" class="form-control input-sm" placeholder="" aria-controls="dataTables-example" name="keywords">	            							
	            							<button class="btn btn-info">搜索</button>
	            					</label>
	            				</div>
	            			</div>
		            	</div>
		                </form>  		
	            		<div class="row">
	            			<div class="col-sm-12">
	            <table id="dataTables-example" class="table table-striped table-bordered table-hover dataTable no-footer" role="grid" aria-describedby="dataTables-example_info">
	                <thead>
	                    <tr role="row">
	                    	<th class="sorting" tabindex="0" aria-controls="dataTables-example" rowspan="1" colspan="1" style="width: 202px;" aria-label="Browser: activate to sort column ascending">ID</th>
	                    	<th class="sorting" tabindex="0" aria-controls="dataTables-example" rowspan="1" colspan="1" style="width: 184px;" aria-label="Platform(s): activate to sort column ascending">类名</th>
	                    	<th class="sorting" tabindex="0" aria-controls="dataTables-example" rowspan="1" colspan="1" style="width: 151px;" aria-label="Engine version: activate to sort column ascending">Pid</th>
	                    	<th class="sorting" tabindex="0" aria-controls="dataTables-example" rowspan="1" colspan="1" style="width: 151px;" aria-label="Engine version: activate to sort column ascending">path</th>
	                    	<th class="sorting" tabindex="0" aria-controls="dataTables-example" rowspan="1" colspan="1" style="width: 109px;" aria-label="CSS grade: activate to sort column ascending">操作</th></tr>
	                </thead>
	                <tbody>
	                <!-- 分类信息显示 -->
	               	@foreach($cates as $k=>$v)
	                	<tr class="gradeA odd" role="row">
	                        <td class="sid">{{$v->id}}</td>
	                        <td class="update">{{$v->cname}}</td>
	                        <td>{{$v->pid}}</td>
	                        <td class="center">{{$v->path}}</td>
	                        <td class="center">
	                        	<!-- <button class="btn btn-warning btn-circle" type="button"><i class="fa fa-times"></i></button> -->
                            	<a href="/admin/cate/delete?id={{$v->id}}" class="btn btn-warning btn-circle" type="button"><i class="fa fa-times"></i></a>
                            	<a href="/admin/cate/edit?id={{$v->id}}" class="btn btn-primary btn-circle" type="button"><i class="fa fa-list"></i></a>
	                        </td>
	                    </tr>
	              	@endforeach
                   </tbody>
	            </table>
	           </div>
	          </div>
	          <div class="row">
	          	<div class="col-sm-6">
	          		<div class="dataTables_info" id="dataTables-example_info" role="status" aria-live="polite">
	          			
	          		</div>
	          	</div>
	          	<div class="col-sm-6">
	          		<div class="dataTables_paginate paging_simple_numbers" id="dataTables-example_paginate">
	          			<!-- laravel提供的分页 -->
	          			{!! $cates->appends($request)->render() !!}	

	          		</div>
	          	</div>
	          </div>
	         </div>
	        </div>
	        <!-- /.table-responsive -->
	        <div class="well">
	        </div>
	    </div>
	    <!-- /.panel-body -->
	</div>
	<!-- /.panel -->
</div>
@endsection
@section('myjs')
	<script type="text/javascript">
		//绑定双击事件 进行修改
			$('.update').dblclick(function(){
				if($(this).attr('isDbl') == 1){return}
				//添加标识
				$(this).attr('isDbl',1);
				//获取原来的用户名
				var yname = $(this).html();
				var id = $(this).prev().html();
				console.log(id);
				var td = $(this);
				//创建input
				var inp = $('<input type="text" value="'+yname+'" />');
				$(this).empty();
				//插入
				$(this).append(inp);
				inp.select();
				//绑定丧失焦点事件
				inp.blur(function(){
				var name = $(this).val();
				//发送ajax
				$.get('{{url("/admin/cate/update")}}',{id:id,cname:name},function(data){
					//判断返回
					if(data == 1){
						//修改成功
						// alert('成功');
						td.empty();
						td.html(name);
						td.removeAttr('isDbl');
					}else{
						//修改失败
						td.empty();
						td.html(yname);
						td.removeAttr('isDbl');

				}
			});
		})

	});
	</script>
@endsection